﻿using System.Collections;
using Spring.Data.NHibernate.Support;

using Project.Model.Rights;
using Project.Repository.Rights;
using NHibernate.Type;
using NHibernate;
using System.Collections.Generic;
using System;
using Project.Repository;

namespace Project.Repository.Rights
{
    public class RoleDao : Repository<Role>, IRoleDao
    {
        public Role GetByName(string name)
        {
            Role role = null;

            IList<Role> roles = this.FindByNamedQuery("Rights.Role.ByName", name, NHibernateUtil.String);
            if (1 == roles.Count)
            {
                role = roles[0];
            }
            else if (1 < roles.Count)
            {
                //throw ExceptionUtil.NewProviderException(Resources.Role_TooManyMatching);
                throw new Exception("Too Many Matching！");
            }

            return role;
        }

        
    }
}
